export default {
	data() {
		return {
			curData: {},
			modalTitle:"",
			modalText: ""
		}
	},
	methods: {
		//确认对话框点击确定触发
		onModalConfirm() {
			//根据弹出对话框时定义的modalConfirmFn决定执行事件
			this.$util.throttle(async () => {
				this[this.modalConfirmFn]();
			})
		},
		
		//取消订单弹窗确认
		cancelOrder(data) {
			console.log(data)
			this.modalTitle="取消救援";
			this.modalText = '您是否确定要取消此次救援';
			this.modalConfirmFn = 'cancelOrderConfirm';
			this.curData = data;
			this.$refs.mixModal.open();
		},
		//取消订单提交
		async cancelOrderConfirm() {
			const res = await this.$request('rescue/cancel', {
				id: this.curData.id
			}, {
				showLoading: true
			})
			if (res.result == 0) {
				this.userComPage()
			}
		},
		async confirmOrderConfirm() {
			const res = await this.$request('rescue/confirm', {
				id: this.curData.id
			}, {
				showLoading: true
			})
			if (res.result == 0) {
				this.userComPage()
			}
		},
		//订单完成弹窗确认
		confirmOrder(data) {
			console.log(data)
			this.modalTitle="完成订单";
			this.modalText = '您是否确定此次救援已完成';
			this.modalConfirmFn = 'confirmOrderConfirm';
			this.curData = data;
			this.$refs.mixModal.open();
		},
		//支付订单
		async payByWx(data) {
			data.uid=uni.getStorageSync('uid');
			this.curData=data;
			const res = await this.$request('rescue/pay', data, {
				showLoading: true
			});
			if (res.result == 0) {
				res.data.body.money=data.money;
				this.PaySingData(res.data.body);
			} else {
				this.$util.msg(res.resultNote)
			}
		},
		PaySingData(data) {
			console.log(data)
			let _this=this;
			uni.requestPayment({
				timeStamp: data.timestamp,
				nonceStr: data.noncestr,
				package: `prepay_id=${data.prepayid}`,
				signType: data.signType,
				paySign: data.sign,
				success(res) {
					uni.redirectTo({
						url:`/pages_servce/servce/success`
					})
				},
				fail(res) {
					if(_this.curData.type!='list'){
						uni.redirectTo({
							url:`/pages_servce/servce/remond`
						})
					}
				}
			});
		},
		userComPage() {
			console.log(this.curData)
			if (this.curData.type == 'list') {
				this.refresh();
			} else {
				uni.navigateBack()
			}
		}
		
	}
}
